<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/15
 * Time: 15:58
 */

namespace App\Http\Controllers;

use Intervention\Image\Facades\Image;
use Illuminate\Http\Request;

class ImageController extends Controller
{
    public function fileForm()
    {
        return view('article/upload');
    }

    public function index(Request $request)
    {
        //$file = $request->file('myfile');
//        $b = file_exists('zhangming.jpg');
//        if($b)
//            return 1;
//        return 0;
        //return file_get_contents($file);
        // create a new image resource from file
      //  $img = Image::make('public/foo.jpg');

// or create a new image resource from binary data
     //   $img = Image::make(file_get_contents('public/foo.jpg'));

// create a new image from gd resource
    //    $img = Image::make(imagecreatefromjpeg('public/foo.jpg'));

// create a new image directly from an url
      //  $img = Image::make('http://example.com/example.jpg');

// create a new image directly from Laravel file upload
        $img = Image::make($request->file('myfile'));
        var_dump($request->file('myfile'));exit;
       // $img = Image::make('zhangming.jpg');

        $img->resize(320, 240);

        $img->insert('watermark.png');

        $img->save('zm_water1.jpg');
    }
}